﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcExceptionManagementSample.Controllers
{
    [HandleError(Order=0)]
    public class HomeController : BaseController
    {
        public ActionResult Index()
        {
            ViewData["Message"] = "Welcome to ASP.NET MVC!";
            return View();
        }

        public ActionResult About()
        {
            return View();
        }

        /// <summary>
        /// If this Controller inherits BaseController you can really remove HandleError attributes since they are overriden
        /// by OnException in BaseController. If you want them to take place, just set filterContext.ExceptionHandled = false in BaseController;
        /// </summary>
        /// <returns></returns>      
        [HandleError(View="Test", ExceptionType=typeof(DivideByZeroException))]
        [HandleError(View = "Test", ExceptionType = typeof(ArgumentOutOfRangeException))]
        [CustomExceptionAttribute]
        public ActionResult DoSomething()
        {
            var arr = new System.Collections.ArrayList();
            var obj = arr[0]; //comment this out if you want to cause DivideByZeroException
            var j = 0;
            var i = 5 / j;
            return View("Index");
        }

       
    }
}
